package org.vectrics.common.db;



import java.sql.Connection;
import java.sql.Statement;
import java.sql.SQLException;
import org.apache.log4j.Logger;
import org.hibernate.Session;


/**
 * @author mmoore
 */
public class JdbcUpdate extends JdbcExecuteBase {
	private transient static Logger log = Logger.getLogger(JdbcUpdate.class);

	public JdbcUpdate(Session session) {
		super(session);
	}
	
	public static int execute(Session session, String updateQuery) {
		JdbcUpdate update = new JdbcUpdate(session);
		return(update.doExecute(updateQuery));
	}
	
	protected int doExecute(String updateQuery) {
		log.debug("execute() called. ");
		int result = -1;

		log.debug("execute() called.  getting connection");
		Connection connection = getDBConnection();
		
		//ResultSet resultSet = null;
		Statement stmt = null;
		
		try {
			log.debug("execute() called.  getting statement");
			stmt = connection.createStatement();
			result = stmt.executeUpdate(updateQuery);
			log.debug("execute() - calling process results on target");
		}
		catch (SQLException ae) {
			log.error("execute() - SQLException", ae);
		}
		finally {
			closeStatement(stmt);
		};
		return(result);
	}
	
}
